<script setup>
import { ref } from 'vue'
import {selectSysMsgService,
    insertSysMsgService,
    updateSysMsgService,
    deleteSysMsgService
} from '@/api/SysManager.js'

const total = ref(0)
const params = ref({
  pageNum:1,
  pageSize:5
})
const handleClick = () => {
  console.log('click')
}

const sysMsgList = ref([])
const sysMsgVo = ref({
      id:'',
      sysNote:'',
      createTime:'',
      createTimeStr:'',
})


const selectSysMsg = async() => {
    const res = await selectSysMsgService(params.value)
    sysMsgList.value = res.data.data
    total.value = res.data.total
}
selectSysMsg()
const dialogVisible = ref(false)

const delRow = (row) => {
    sysMsgVo.value = row
    deleteSysMsgService(sysMsgVo.value)
    sysMsgVo.value = {}
    ElMessage.success('成功！')
    selectSysMsg()
}
const editInsertBtn = () => {
    dialogVisible.value=true
    sysMsgVo.value={}
}
const confirmClick = async ()=>{
  await insertSysMsgService(sysMsgVo.value)
  ElMessage.success('成功！')
  sysMsgVo.value={}
  dialogVisible.value =  false
  selectSysMsg()
}


</script>

<template>
  <div>
    <div class="cus-header">
        <el-card>
            <div style="display: flex;justify-content: space-between;">
                <div class="search">
                    <div>
                        课程：
                        <el-input v-model="input" style="width: 240px" placeholder="请输入课程名称" />
                    </div>
                    <div style="margin-left: 20px;">
                        课节：
                        <el-input v-model="input" style="width: 240px" placeholder="请输入课节" />
                    </div>
                    <div style="margin-left: 20px;">
                        姓名：
                        <el-input v-model="input" style="width: 240px" placeholder="请输入姓名" />
                    </div>
                    <div style="margin-left: 20px;">
                        <el-button style="width: 80px;" type="primary">搜索</el-button>
                    </div>
                </div>
                <div class="insert">
                    <el-button style="width: 80px;" type="primary" @click="editInsertBtn">新增</el-button>
                </div>
            </div>
            
        </el-card>
    </div>
    <div class="cus-body">
        <el-card style="min-height: 650px;">
            <el-table :data="sysMsgList" style="width: 100%">
                <el-table-column fixed prop="id" label="编号" width="150" />
                <el-table-column prop="sysNote" label="公告描述" width="120" />
                <el-table-column prop="createTimeStr" label="创建时间" width="1020" />
                <el-table-column fixed="right" label="操作" min-width="120">
                    <template #default="{row}">
                        <el-button link type="primary" size="small" @click="delRow(row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
  </div>

  <el-dialog
    v-model="dialogVisible"
    title="公告"
    width="500"
    :before-close="handleClose"
  >
    公告内容：<el-input v-model="sysMsgVo.sysNote" style="width: 240px" placeholder="请输入" />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmClick">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>


<style lang="scss" scoped>
    .flex-row{
        display: flex;
        flex-direction: row;
    }
    .cus-header{
        .search{
            display: flex;
            flex-direction: row;
        }
    }
    .cus-body{
        margin-top: 15px;
    }
</style>